<?php

/**
 * Description of Comment Controller
 *
 * @author Huỳnh
 */

class Admin_Cms_BarcodeController extends My_Controller_Action {
	
	public function init(){
		parent::init();
		
		$auth = Zend_Auth::getInstance();
        
        if(!$auth->hasIdentity())
        { 
            $this->_redirect("user/account/login");
        }
        
        if ($this->isAccess($auth->getIdentity()->group_id, 10))
        {
			//to do
		} else {
            die("Access denied");
        }
	}   
	
	public function indexAction()
	{			
		$deal_id = $this->_request->getParam("deal_id");
		if($deal_id == null)
		{
			$this->_redirect("admin_cms/deal");
		}
		
		if($this->_request->isPost())
		{
			$checkbox = $_POST['checkbox'];
			$status = $_POST['status'];
			
			$model = $this->loadModel('admin_cms', 'Item');
			for($i = 0; $i < count($checkbox); $i++)
			{
				$item = $model->getItemById($checkbox[$i]);
				$item->barcode_status = $status;
				$item->save();
			}
		}
		
		$this->view->order_status = Zend_Registry::get("order_status");
		$this->view->barcode_status = Zend_Registry::get("barcode_status");
		
        $this->view->rightAdminModules('right');
        
        $this->view->by = $this->_request->getParam("by", "o.created");
        $this->view->order = $this->_request->getParam("order", "desc");
        
        Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
        $model = $this->loadModel('admin_cms', 'Item');
        $this->view->paginator = $model->getItemsByDealId($deal_id, $this->_getParam('page', 1), $this->view->by.' '.$this->view->order);
        
        $this->view->deal_id = $deal_id;
    }
}
